package com.itcast.activiti.cmd;

import lombok.AllArgsConstructor;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity;
import org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntityImpl;
import org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntityManager;

import java.util.List;

@AllArgsConstructor
public class UpdateHistoricActivityCmd implements Command<Void> {
    protected String processInstanceId;
    protected String processDefinitionId;
    protected List<HistoricActivityInstance> list;

    @Override
    public Void execute(CommandContext commandContext) {
        HistoricActivityInstanceEntityManager historicActivityInstanceEntityManager = commandContext.getHistoricActivityInstanceEntityManager();
        for (HistoricActivityInstance historicActivityInstance : list) {
            HistoricActivityInstanceEntityImpl historicActivityInstanceEntity = (HistoricActivityInstanceEntityImpl) historicActivityInstance;
            historicActivityInstanceEntity.setProcessDefinitionId(processDefinitionId);
            historicActivityInstanceEntityManager.insert(historicActivityInstanceEntity);
        }
        return null;
    }
}
